<?php

namespace JsonLowCode\UI;

use JsonLowCode\Schema;
use JsonLowCode\Traits\Events\HasModelValueEvent;
use JsonLowCode\Traits\Props\HasDefaultValue;
use JsonLowCode\Traits\Props\HasDisabled;
use JsonLowCode\Traits\Props\HasSize;
use JsonLowCode\Traits\Props\HasValue;

/**
 * Checkboxes组件
 * @method static Checkboxes make(string|int|bool $value = null) Checkbox组件
 */
class Checkboxes extends Schema
{
    protected string $componentName = "CheckBoxFieldAbstract";

    use HasDisabled, HasSize, HasValue, HasDefaultValue;

    use HasModelValueEvent;

    /**
     * @param string|int|bool|null $value
     */
    public function __construct(string|int|bool $value = null)
    {
        parent::__construct();
        $this->prop('value', $value);
    }

    /**
     * @param array $options
     * @return $this
     */
    public function options(array $options = []): static
    {
        return $this->prop("options", $options);
    }

    /**
     * 发生变化时触发的回调方法
     * @param string $event (value: boolean) => void
     * @return $this
     */
    public function onChange(string $event = "(value) => {}"): static
    {
        return $this->events('onChange', $event);
    }
}
